home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / MIDI_MAN / CMIDICLI.C < prev    next >
Text File  |  1992-03-07  |  4KB  |  124 lines

  1. //--- CMIDIClient.c ---------------------------------------------------------------------
  2. // Copyright ⌐ Paul Ferguson, 1990, 1991, 1992.  All rights reserved.
  3. //
  4. // Superclass:  CObject
  5. // Subclasses:  None
  6. //
  7. // Description:
  8. //    CMIDIClient.c defines a MIDI Manager client object.
  9. //
  10. //    For use with THINK C 5.0, the accompanying THINK Class Library (TCL), and MIDI
  11. //    Manager 2.0. Refer to the accompanying Microsoft Word document for complete
  12. //    details about MIDI Manager objects.
  13. //
  14. //    If you have comments or questions about this code, you can reach me on
  15. //    CompuServe at 70441,3055.
  16. //
  17. //--------------------------------------------------------------------------------------
  18. //---- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE ----
  19. //--------------------------------------------------------------------------------------
  20. //    If you are not familiar with programming the Apple MIDI Manager, refer to the
  21. //    "MIDI Management Tools" Version 2.0, available from APDA.  You MUST have the
  22. //    software (MIDI.H and the library) from this package in order to use these objects.
  23. //    It will not work without this.
  24. //--------------------------------------------------------------------------------------
  25. //    REVISION HISTORY:
  26. //        August ??, 1990            - Original release (1.0).
  27. //        November 5, 1990        - Added checks for midiMgrVer to most methods.
  28. //        August 1991                - updated for THINK C 5.0 as version 2.0
  29. //--------------------------------------------------------------------------------------
  30.  
  31. #include "CMIDIClient.h"                    // This code's header file
  32.  
  33. extern    OSType            gSignature;            // Used to register client
  34.  
  35. //--- gMIDIClient (global variable) --------------------------------------
  36. // Because these objects are designed only for a single MIDI client, we
  37. // define this global to hold it.
  38. //------------------------------------------------------------------------
  39.  
  40. CMIDIClient * gMIDIClient = (CMIDIClient *) 0;
  41.  
  42.  
  43. //--- CMIDIClient::IMIDIClient -------------------------------------------
  44. // Initialize this object.
  45. //
  46. // Sign into the MIDI Manager.  Save the midiMgrVerNum.  It signs
  47. // in with the application's name, and tries to find it's BNDL type.
  48. //
  49. // NOTE:    Only one instance of a MIDI Manager Client can be made, with
  50. //            the current design of these objects.  Other methods assume
  51. //            that the 'gMIDIClient' variable points to a valid instance
  52. //            of this type.
  53. //------------------------------------------------------------------------
  54.  
  55. OSErr CMIDIClient::IMIDIClient(short theIconID)
  56. {
  57.     OSErr            err;
  58.     Handle            theIconHndl;        // Used by MIDISignIn
  59.     Str255            theName;            // me too...
  60.     short            i;                    // Junk variables
  61.     Handle            h;
  62.  
  63. // Make sure MIDIMgr is installed and save version num.
  64.  
  65.     midiMgrVerNum   = SndDispVersion(midiToolNum);
  66.  
  67.     if (midiMgrVerNum == 0)                // Damn!  Things were going so well...
  68.     {
  69.         return ErrNoMIDI;                // No MIDI driver seems to be loaded
  70.     }
  71.  
  72. //--- Sign in to the MIDI Manager. -------------------------------
  73.  
  74.     theIconHndl = GetResource('ICN#',theIconID);    // Let's get our icon
  75.     CheckResource(theIconHndl);            // Just checkin'...
  76.     GetAppParms(theName, &i, &h);        // Get the Name of this application
  77.  
  78.     err = MIDISignIn(gSignature,         // Use application signature
  79.                         0L,                // Don't need refCon
  80.                         theIconHndl,
  81.                         theName);        // Use it to name the MIDI client
  82.     ReleaseResource(theIconHndl);
  83.     if (err)
  84.         midiMgrVerNum = 0;                // Indicates problem
  85.     return err;
  86. }
  87.  
  88. //--- CMIDIClient::Dispose ----------------------------------------
  89. // Save connections, sign out of MIDI Manager.
  90. //-----------------------------------------------------------------
  91.  
  92. void CMIDIClient::Dispose(void)
  93. {
  94.      if (midiMgrVerNum)                    // If we are signed in to MM
  95.          MIDISignOut(gSignature);
  96.     inherited::Dispose();                // Call CObject method
  97. }                                        // It's Miller Time╔
  98.  
  99. //--- CMIDIClient:: trival methods --------------------------------
  100.  
  101. MIDIIDListHdl    CMIDIClient::GetPorts(void)
  102. {
  103.     return (midiMgrVerNum) ? MIDIGetPorts(gSignature) : (MIDIIDListHdl)0;
  104. }
  105.  
  106. Boolean CMIDIClient::WorldChanged(void)
  107. {
  108.     return (midiMgrVerNum) ? MIDIWorldChanged(gSignature) : FALSE;
  109. }
  110.  
  111. unsigned long CMIDIClient::GetVerNum(void)
  112. {
  113.     return midiMgrVerNum;
  114. }
  115.  
  116. unsigned short CMIDIClient::GetShortVerNum(void)
  117. {
  118.     register unsigned long version = midiMgrVerNum;
  119.     version >>= 16;
  120.     return (unsigned short) version;
  121. }
  122.  
  123. // end of CMIDIClient.c
  124.